package com.itheima.netmarket.impl.view;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.itheima.netmarket.GlobalConstants;
import com.itheima.netmarket.impl.view.manager.UIManagerImpl;
import comitheima.netmarket.R;

/**
 * 选择优惠
 * 
 * @author yangxin
 */
public class PaymentRemarkView extends MainView {

	/**
	 * 回结算中心
	 */
	private TextView headBackText;
	/**
	 * 添加礼品卡
	 */
	private TextView invoiceSaveText;
	/**
	 * 优惠一
	 */
	private RelativeLayout paymentRemarkRel;
	/**
	 * 优惠二
	 */
	private RelativeLayout paymentRemarkRRel;
	/**
	 * 优惠显示一
	 */
	private ImageView paymentRemarkImg;
	/**
	 * 优惠显示二
	 */
	private ImageView paymentRemarkRImg;
	private TextView paymentRemarkText;
	private TextView paymentRemarkRText;

	public PaymentRemarkView(Context context, Bundle bundle) {
		super(context, bundle);
	}

	public PaymentRemarkView(Context context) {
		super(context);
	}

	@Override
	public View getmView() {
		View view = View.inflate(context, R.layout.payment_remark_activity, null);
		init(view);
		return view;
	}

	/**
	 * 初始化
	 * 
	 * @param view
	 */
	private void init(View view) {
		headBackText = (TextView) view.findViewById(R.id.head_back_text);
		invoiceSaveText = (TextView) view.findViewById(R.id.invoice_save_text);
		paymentRemarkRel = (RelativeLayout) view.findViewById(R.id.payment_remark_rel);
		paymentRemarkRRel = (RelativeLayout) view.findViewById(R.id.payment_remark_r_rel);
		paymentRemarkImg = (ImageView) view.findViewById(R.id.payment_remark_img);
		paymentRemarkRImg = (ImageView) view.findViewById(R.id.payment_remark_r_img);
		paymentRemarkText = (TextView) view.findViewById(R.id.payment_remark_text);
		paymentRemarkRText = (TextView) view.findViewById(R.id.payment_remark_r_text);

		setOnclick();
		clearChoose();
	}

	private void setOnclick() {
		headBackText.setOnClickListener(this);
		invoiceSaveText.setOnClickListener(this);
		paymentRemarkRel.setOnClickListener(this);
		paymentRemarkRRel.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.head_back_text:
			Bundle bundle = new Bundle(); 
			bundle.putString("remarkContent", GlobalConstants.paymentRemarkContent);
			// 回结算中心
			UIManagerImpl.getInstance().changeViewWithBundle(PayCenterView.class, bundle);
			break;
		case R.id.invoice_save_text:
			// 添加
			Toast.makeText(context, "亲，这个模块还没做哟", Toast.LENGTH_LONG).show();
			break;
		case R.id.payment_remark_rel:
			// 优惠一
			if (paymentRemarkImg.getVisibility() == View.GONE) {
				clearChoose();
				paymentRemarkImg.setVisibility(View.VISIBLE);
				GlobalConstants.paymentRemarkContent = paymentRemarkText.getText().toString();
			} else {
				paymentRemarkImg.setVisibility(View.GONE);
			}
			break;
		case R.id.payment_remark_r_rel:
			// 优惠二
			if (paymentRemarkRImg.getVisibility() == View.GONE) {
				clearChoose();
				paymentRemarkRImg.setVisibility(View.VISIBLE);
				GlobalConstants.paymentRemarkContent = paymentRemarkRText.getText().toString();
			} else {
				paymentRemarkRImg.setVisibility(View.GONE);
			}
			break;
		}
	}

	/**
	 * 清除选择
	 */
	private void clearChoose() {
		paymentRemarkImg.setVisibility(View.GONE);
		paymentRemarkRImg.setVisibility(View.GONE);
	}

}
